package logger

import (
	"fmt"
	"gitee-lfs-multipart-transfer/internal/common"
	"io"
	"os"
)

type Logger struct {
	w      io.Writer
	enable bool
}

func NewLogger(w io.Writer) *Logger {
	return &Logger{
		w: w,
		enable: os.Getenv(common.ENV_UPLOADER_LOG_ENABLE) == "true" ||
			os.Getenv(common.ENV_UPLOADER_LOG_ENABLE) == "1",
	}
}

func (l *Logger) Println(v ...any) {
	if l.enable {
		fmt.Fprintln(l.w, v...)
	}
}

func (l *Logger) Printf(format string, v ...any) {
	if l.enable {
		fmt.Fprintf(l.w, format, v...)
	}
}
